from PySide import QtGui
from PySide import QtCore
	
class MemberItem(QtGui.QGraphicsLineItem):
	
	def __init__(self, member):
		super(MemberItem, self).__init__()
		self.member = member
		self.setPen(QtGui.QPen(QtCore.Qt.green, 3))
		self.setZValue(0)
		self.updateMember()
	
	def updateMember(self):
		x1 = self.member.nodes[0].position.x[0]
		y1 = self.member.nodes[0].position.x[1]
		x2 = self.member.nodes[1].position.x[0]
		y2 = self.member.nodes[1].position.x[1]
		self.setLine(x1, -y1, x2, -y2)

class MemberNameItem(QtGui.QGraphicsTextItem):
	
	def __init__(self, member):
		super(MemberNameItem, self).__init__()
		self.member = member
		self.setFont(QtGui.QFont('Decorative', 8))
		self.setZValue(2)
		self.updateMember()
	
	def updateMember(self):
		x1 = self.member.nodes[0].position.x[0]
		y1 = self.member.nodes[0].position.x[1]
		x2 = self.member.nodes[1].position.x[0]
		y2 = self.member.nodes[1].position.x[1]
		self.setPlainText(self.member.name)
		w = self.boundingRect().width()/2
		h = self.boundingRect().height()/2
		self.setPos((x1+x2)/2 - w, -(y1+y2)/2 - h)

class NodeItem(QtGui.QGraphicsEllipseItem):
	
	def __init__(self, node):
		super(NodeItem, self).__init__()
		self.node = node
		self.setBrush(QtGui.QBrush(QtCore.Qt.red))
		self.setPen(QtGui.QPen(QtCore.Qt.black, 3))
		self.setZValue(1)
		self.updateNode()
	
	def updateNode(self):
		x = self.node.position.x[0]
		y = self.node.position.x[1]
		self.setRect(x-4, -y-4, 8, 8)

class NodeNameItem(QtGui.QGraphicsTextItem):
	
	def __init__(self, node):
		super(NodeNameItem, self).__init__()
		self.node = node
		#self.setPen(QtGui.QPen(QtCore.Qt.black, 0))
		self.setFont(QtGui.QFont('Decorative', 8))
		self.setZValue(3)
		self.updateNode()
	
	def updateNode(self):
		x = self.node.position.x[0]
		y = self.node.position.x[1]
		self.setPos(x, -y)
		self.setPlainText(self.node.name)
